package com.cslg.ac.demo.dao.like;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.cslg.ac.demo.dao.like.po.LikePO;

@Mapper
public interface LikeDAO {

	final String LIKE_TABLE = "e_like";
	final String INSERT_FIELDS = " id, type, targetId ";
	
	@Select({"select targetId from", LIKE_TABLE, " where id = #{id} and type = #{type}"})
	int[] select(@Param("id") int id, @Param("type") int type);
	
	@Select({"select id from ", LIKE_TABLE, "where targetId = #{targetId} and type = #{type}"})
	int[] selectFollow(@Param("targetId") int targetId, @Param("type") int type);
	
	@Select({"select id from", LIKE_TABLE, "where id = #{id} and type = #{type} and targetId = #{targetId} limit 1"})
	Integer exist(LikePO likePO);
	
	@Insert({"insert into", LIKE_TABLE, "(", INSERT_FIELDS, ") values (", "#{id}, #{type}, #{targetId})"})
	void insert(LikePO likePO);
	
	@Delete({"delete from", LIKE_TABLE, " where id = #{id} and type = #{type} and targetId = #{targetId}"})
	void delete(LikePO likePO);
	
}
